#pragma once
#include "..\DXAMLCommon.h"
#include "Utf16CharacterSource.h"


class CodePageCharacterSource :
	public Utf16CharacterSource
{

private: 
	virtual CodePageCharacterSource & operator=(CodePageCharacterSource & __formal);

public: 
	CodePageCharacterSource(struct IMalloc * pMalloc);
	virtual ~CodePageCharacterSource();
	virtual bool fCodePageSrc();
	void SetCodePage(XUINT32);
	virtual XINT32 GetCharacterSize();
	virtual InputSource * GetInputSource();
	virtual void SetInputSource(InputSource * pInputSource);
	virtual void SetFirstInputBuffer(XUINT8 * pbInput, XUINT8 * pbSeg, unsigned long cbInput, unsigned long cbValid);
	virtual void ReleaseInputBuffer(XUINT8 * * ppbInput, XUINT8 * * ppbSeg, unsigned long * pcbInput, unsigned long * pcbValid);
	virtual wchar_t GetCharacter();
	virtual HRESULT Read(void * pv, unsigned long cb, unsigned long * pcbRead);
	XUINT64 GetStreamPosition0(XUINT8 *);
	virtual void GetExtendedPosition(struct Position * pPosition);
	virtual void SetExtendedPosition(struct Position * pPosition);
	unsigned long GetSrcBufferSize();
	void CopySrcBuffer(XUINT8 * pbStart, unsigned long cbSpace, unsigned long * pcchCurrOffSet, unsigned long * pcchSegOffSet, unsigned long * pcchLineOffset, unsigned long * pcchLineShiftedOffset, unsigned long * pcchEndOffset, unsigned long * pcchSaved, unsigned long * pcchLastRead);
protected: 
	virtual HRESULT Convert(XUINT8 *, XUINT32 *, wchar_t *, XUINT32 *) = 0;
	virtual unsigned long GetConvertSize(wchar_t *, unsigned long) = 0;
	virtual unsigned long ConvertToMultiByte(wchar_t *, unsigned long, char *, unsigned long) = 0;
	virtual void CopyFrom(CharacterSource & other);
	virtual void CopyFrom(CodePageCharacterSource & other);

	class CodePageInputSource :
		public InputSource
	{
	public: 
		CodePageInputSource(struct IMalloc *);
		virtual HRESULT Read(void * pv, unsigned long cb, unsigned long * pcbRead);
	private: 
		CodePageCharacterSource * Px();
	};

	CodePageInputSource _inputSource;


	InputSource * _pInputSource0;
	bool _fEndOfInput0;
	unsigned long _ulCapacity0;
	XUINT8 * _pbStart0;
	XUINT8 * _pbCurr0;
	unsigned long _ulSize0;
	XUINT64 _ullStartPosition0;
	XUINT8 * _pbLastRead0;
	XUINT32 _uiCodePage;
	XUINT8 * _pbXmlDecl;

};